using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Webadmin_ConfigSiteOption : System.Web.UI.Page
{
    public DataTable _dt = null;
    public DataTable _dtSiteOption = null;
    //----------------------------------------------------------
    public DataRow _SiteOption = null;
    public DataRow _AdminLang = null;
    public dbConnection _DB = new dbConnection();
    public string _Act = "";
    private string _SiteNote = "SiteOption";
    private string _LangNote = "SiteOption";
    private void initSiteLang()
    {
       
        //-------------       
        if (!Request.Url.AbsoluteUri.Contains(Session["Page"].ToString()))
        {
            Session["Page"] = Request.Url.AbsoluteUri.Split('?')[0];
        }
        //---------
        Session["Lang"] = Request.QueryString["Lang"] == null ? Session["Lang"] : Request.QueryString["Lang"];
        Session["Lang"] = bzAdminLang.checkLang(Session["Lang"].ToString());
        _SiteOption = new bzSiteOption("SiteAdmin", _SiteNote).SiteOption;
        _AdminLang = new bzAdminLang(Session["Lang"].ToString(), _LangNote).AdminLang;


        //---------       
        if (!bzCheckAdminUser.checkUserPermission(Session["AdminUser"].ToString(), Session["AdminLevel"].ToString(), Session["IP"].ToString(), Session["LoginID"].ToString(), Session["GroupUser"].ToString(), Session["Page"].ToString(), bzCheckAdminUser.View))
        {
            Response.Redirect(bzStringClass.AlertPermission);
        }
        //--------
        _Act = Request.QueryString["Act"] == null ? "" : Request.QueryString["Act"];
        this.loadAction();
    }

    //---------
    private void loadAction()
    {
        if (!this.Page.IsPostBack)
            switch (_Act)
            {
                case "Update": this.updateSiteOption();  break;
            }
        this.lblNavigator.Text = _AdminLang["MenuConfig"].ToString() + _AdminLang["GeneralArrow"].ToString() + _AdminLang["MenuConfigSiteOption"].ToString();
        _dt = _DB.getDataTable("SP_getSiteOptionGroup");
    }
    //-----------------------------------------------------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang();
        
    }
    public DataTable loadSiteOption(string groupName)
    {
        SqlParameter[] p = new SqlParameter[2];
        p[0]=new SqlParameter("@GroupOption", groupName);
        p[1] = new SqlParameter("@Note", "%%");
        return _DB.getDataTable("SP_getSiteOption", p);
    }
    private void updateSiteOption()
    {
        if (bzCheckAdminUser.checkUserPermission(Session["AdminUser"].ToString(),Session["AdminLevel"].ToString(),Session["IP"].ToString(),Session["LoginID"].ToString(),Session["GroupUser"].ToString(),Session["Page"].ToString(),bzCheckAdminUser.Edit))
        {
            _dtSiteOption = _DB.getDataTable("SP_getSiteOption_All");
            foreach (DataRow dr in _dtSiteOption.Rows)
            {
                SqlParameter[] p = new SqlParameter[2];
                p[0] = new SqlParameter("@Name", dr["Name"].ToString());                
                p[1] = new SqlParameter("@Value", Request.Form[dr["Name"].ToString()] == null ? dr["ValueSelect"].ToString() : Request.Form[dr["Name"].ToString()]);               
                _DB.updateData("SP_updateSiteOption",p);
            }
            Response.Write(bzStringClass.addStringAlert(_AdminLang["Success"].ToString()));
        }
        else Response.Redirect(bzStringClass.AlertPermission);
    }
}
